package com.kumarn.android.catdroid.full;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;

public class CatDroid extends BroadcastReceiver{

	private SharedPreferences pref;
	private MediaPlayer mediaPlayer;

	@Override
    public void onReceive(Context context, Intent intent) {

		String ACTION = intent.getAction();
		pref = context.getSharedPreferences("CatDroidPref",Context.MODE_WORLD_READABLE|Context.MODE_WORLD_WRITEABLE);

		//ケーブル接続
		if(ACTION.equals(Intent.ACTION_POWER_CONNECTED) && pref.getBoolean("ACTION_POWER_CONNECTED", false)){

			mediaPlayer = MediaPlayer.create(context,R.raw.cat);
			mediaPlayer.start();

		//ケーブル取り外し
		}else if(ACTION.equals(Intent.ACTION_POWER_DISCONNECTED) && pref.getBoolean("ACTION_POWER_DISCONNECTED", false)){

			mediaPlayer = MediaPlayer.create(context,R.raw.cat);
			mediaPlayer.start();

		//スクリーンON
		}else if(ACTION.equals(Intent.ACTION_SCREEN_ON) && pref.getBoolean("ACTION_SCREEN_ON", false)){

			mediaPlayer = MediaPlayer.create(context,R.raw.cat);
			mediaPlayer.start();

		//スクリーンOFF
		}else if(ACTION.equals(Intent.ACTION_SCREEN_OFF) && pref.getBoolean("ACTION_SCREEN_OFF", false)){

			mediaPlayer = MediaPlayer.create(context,R.raw.cat);
			mediaPlayer.start();

		//日付変更
		}else if(ACTION.equals(Intent.ACTION_DATE_CHANGED) && pref.getBoolean("ACTION_DATE_CHANGED", false)){

			mediaPlayer = MediaPlayer.create(context,R.raw.cat);
			mediaPlayer.start();
		}
    }
}